require "import"
import "tools"
activity.setContentView("vScreenshot_")
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS).setStatusBarColor(0xff4DB6AC)
page.addOnPageChangeListener{
  onPageScrolled=function(a,b,c)
    bar.setX((a+b)*activity.getWidth()/2)
  end}
one.onClick=function()
  page.showPage(0)
end
more.onClick=function()
  page.showPage(1)
end
oDir.text=LUA_SD.."/avHandle/output/"
iDir.onClick=function()
  ChoiceFile(LUA_SD,function(dir)
    iDir.text=dir
    vi.setVideoURI(Uri.parse(dir)).start().setMediaController(MediaController(this))
  end)
end
oDir.onClick=function()
  ChoicePath(LUA_SD,function(dir)
    oDir.text=dir.."/"
  end)
end
jump_one.background=btBackground
screenshot_one.background=btBackground
screenshot_two.background=btBackground
jump_two1.background=btBackground
jump_two2.background=btBackground
jump_one.onClick=function()
  vi.start()
  if pos.text:find(":") then
    local arr=String(pos.text).split(":")
    vi.seekTo( (((tonumber(arr[0])*60+tonumber(arr[1]))*60+ tonumber(arr[2]))*1000))
   else
    vi.seekTo(tonumber(pos.text)*1000)
  end
  vi.pause()
end
screenshot_one. onClick=function()
  if fbl_one.text~=""
    activity.newActivity("handle",{ "-i "..iDir.text.." -ss ".. pos.text.." -y -vframes 1 -s "..fbl_one.text.." "..oDir.text..pos.text..".jpg"})
   else
    activity.newActivity("handle",{ "-i "..iDir.text.." -ss ".. pos.text.." -y -vframes 1 "..oDir.text..pos.text..".jpg"})
  end
end

jump_two1.onClick=function()
  vi.start()
  if pos1.text:find(":") then
    local arr=String(pos1.text).split(":")
    vi.seekTo( (((tonumber(arr[0])*60+tonumber(arr[1]))*60+ tonumber(arr[2]))*1000))
   else
    vi.seekTo(tonumber(pos1.text)*1000)
  end
  vi.pause()
end
jump_two2.onClick=function()
  vi.start()
  if pos2.text:find(":") then
    local arr=String(pos2.text).split(":")
    vi.seekTo( (((tonumber(arr[0])*60+tonumber(arr[1]))*60+ tonumber(arr[2]))*1000))
   else
    vi.seekTo(tonumber(pos2.text)*1000)
  end
  vi.pause()
end
screenshot_two.onClick=function()
  if pos1.text~="" and pos2.text~="" and period.text~=""
    local cmd=""
    if fbl_more.text~=""
      cmd="-i "..iDir.text.." -ss "..pos1.text.." -y -t "..pos2.text.." -r "..tostring(1/tonumber(period.text)).." -s "..fbl_more.text.." "..oDir.text.."%d.jpg"
     else
      cmd="-i "..iDir.text.." -ss "..pos1.text.." -y -t "..pos2.text.." -r "..tostring(1/tonumber(period.text)).." "..oDir.text.."%d.jpg"
    end
    activity.newActivity("handle",{cmd})
   else
    print("请填写完整")
  end
end